package com.servlet;

import com.Imp.*;
import com.entity.Hire;
import com.mapper.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HireController extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String op=request.getParameter("op");
        String deliverymanId= request.getParameter("username");
        String storeId= request.getParameter("storeId");
        HireMapper hireMapper = new HireMapperImpl();
        if(op.equals("delete")){
            Hire hire = new Hire();
            hire.setStoreId(storeId);
            hire.setDeliverymanId(deliverymanId);
            hireMapper.deleteHire(hire);
            // 设置请求参数
            String redirectUrl = "/myDeliveryman.jsp";
            //重定向到指定页面
            response.sendRedirect(redirectUrl);
        }
        else if(op.equals("add")){
            Hire hire = new Hire();
            hire.setStoreId(storeId);
            hire.setDeliverymanId(deliverymanId);
            hireMapper.addToHire(hire);
            String redirectUrl = "/myDeliveryman.jsp";
            // 重定向到指定页面
            response.sendRedirect(redirectUrl);
        }
    }
}
